file1=open(r"d:\a.txt","r")
text=file1.read()
print("读取的文件内容",text)
text_replace=text.replace("python","中国")
print("替换之后的内容",text_replace)
file1.close()
file2=open(r"d:\a.txt","w")
file2.write(text_replace)
# file2.write("我爱你中国,我爱你")
file2.close()
# #比较反复的关闭,他自己帮我们进行关闭
# with open(r"d:\a.txt","r") as file:
#     text=file.read()
#     print(text)


